package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebWithdrawController;
import com.web.entity.WithdrawApply;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface WithdrawApplyMapper {


    @Delete({
            "delete from t_withdraw_apply",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_withdraw_apply (m_id, name, ",
            " phone,reason, account, amt,type,",
            " bank_name, card_no, ",
            " poundage_rate, poundage, ",
            " status,record_id, create_time, ",
            " modify_time)",
            " values (#{mId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
            " #{phone,jdbcType=VARCHAR},#{resaon,jdbcType=VARCHAR}, #{account,jdbcType=VARCHAR},#{amt,jdbcType=DECIMAL},#{type,jdbcType=INTEGER}, ",
            " #{bankName,jdbcType=VARCHAR}, #{cardNo,jdbcType=VARCHAR}, ",
            " #{poundageRate,jdbcType=DECIMAL}, #{poundage,jdbcType=DECIMAL}, ",
            " #{status,jdbcType=INTEGER},#{recordId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, ",
            " #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(WithdrawApply record);

    @InsertProvider(type = WithdrawApplySqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(WithdrawApply record);


    @Select({
            "select",
            " id, m_id, name, phone,reason, account,amt,type, bank_name, card_no, poundage_rate, poundage, ",
            " status,record_id, create_time, modify_time",
            " from t_withdraw_apply",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amt", property = "amt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "bank_name", property = "bankName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_no", property = "cardNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "poundage_rate", property = "poundageRate", jdbcType = JdbcType.DECIMAL),
            @Result(column = "poundage", property = "poundage", jdbcType = JdbcType.DECIMAL),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    WithdrawApply selectByPrimaryKey(Long id);


    @UpdateProvider(type = WithdrawApplySqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WithdrawApply record);

    @Update({
            "update t_withdraw_apply",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " name = #{name,jdbcType=VARCHAR},",
            " phone = #{phone,jdbcType=VARCHAR},",
            " reason = #{reason,jdbcType=VARCHAR},",
            " account = #{account,jdbcType=VARCHAR},",
            " amt = #{amt,jdbcType=DECIMAL},",
            " type = #{type,jdbcType=INTEGER},",
            " bank_name = #{bankName,jdbcType=VARCHAR},",
            " card_no = #{cardNo,jdbcType=VARCHAR},",
            " poundage_rate = #{poundageRate,jdbcType=DECIMAL},",
            " poundage = #{poundage,jdbcType=DECIMAL},",
            " status = #{status,jdbcType=INTEGER},",
            " record_id = #{recordId,jdbcType=BIGINT},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(WithdrawApply record);

    @SelectProvider(type = WithdrawApplySqlProvider.class, method = "selectAllwithdraws")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reason", property = "reason", jdbcType = JdbcType.VARCHAR),
            @Result(column = "account", property = "account", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amt", property = "amt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "bank_name", property = "bankName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "card_no", property = "cardNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "poundage_rate", property = "poundageRate", jdbcType = JdbcType.DECIMAL),
            @Result(column = "poundage", property = "poundage", jdbcType = JdbcType.DECIMAL),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Page<WithdrawApply> selectAllwithdraws(WebWithdrawController.WithdrawColumns withdrawColumns);


    @Select({
            "select count(0) from t_withdraw_apply where status=0 "
    })
    int countWaiting();

    @Select({
            "select sum(amt) from t_withdraw_apply where status=0 and m_id= #{mId,jdbcType=BIGINT} and type= #{type,jdbcType=INTEGER} "
    })
    Double countFreezeByMid(@Param("mId") Long mId,@Param("type") int type);
}